home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / SocketOutputStream.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  98 lines

  1. /*
  2.  * @(#)SocketOutputStream.java    1.12 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.net;
  16.  
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19.  
  20. /**
  21.  * This stream extends FileOutputStream to implement a
  22.  * SocketOutputStream. Note that this class should <b>NOT</b> be
  23.  * public.
  24.  *
  25.  * @version     1.12, 07/01/98
  26.  * @author     Jonathan Payne
  27.  * @author    Arthur van Hoff
  28.  */
  29. class SocketOutputStream extends FileOutputStream
  30. {
  31.     private SocketImpl impl;
  32.     private byte temp[] = new byte[1];
  33.     
  34.     /**
  35.      * Creates a new SocketOutputStream. Can only be called
  36.      * by a Socket. This method needs to hang on to the owner Socket so
  37.      * that the fd will not be closed.
  38.      * @param impl the socket output stream inplemented
  39.      */
  40.     SocketOutputStream(SocketImpl impl) throws IOException {
  41.     super(impl.getFileDescriptor());
  42.     this.impl = impl;
  43.     }
  44.  
  45.     /**
  46.      * Writes to the socket.
  47.      * @param b the data to be written
  48.      * @param off the start offset in the data
  49.      * @param len the number of bytes that are written
  50.      * @exception IOException If an I/O error has occurred.
  51.      */
  52.     private native void socketWrite(byte b[], int off, int len)
  53.     throws IOException;
  54.  
  55.     /** 
  56.      * Writes a byte to the socket. 
  57.      * @param b the data to be written
  58.      * @exception IOException If an I/O error has occurred. 
  59.      */
  60.     public void write(int b) throws IOException {
  61.     temp[0] = (byte)b;
  62.     socketWrite(temp, 0, 1);
  63.     }
  64.  
  65.     /** 
  66.      * Writes the contents of the buffer <i>b</i> to the socket.
  67.      * @param b the data to be written
  68.      * @exception SocketException If an I/O error has occurred. 
  69.      */
  70.     public void write(byte b[]) throws IOException {
  71.     socketWrite(b, 0, b.length);
  72.     }
  73.  
  74.     /** 
  75.      * Writes <i>length</i> bytes from buffer <i>b</i> starting at 
  76.      * offset <i>len</i>.
  77.      * @param b the data to be written
  78.      * @param off the start offset in the data
  79.      * @param len the number of bytes that are written
  80.      * @exception SocketException If an I/O error has occurred.
  81.      */
  82.     public void write(byte b[], int off, int len) throws IOException {
  83.     socketWrite(b, off, len);
  84.     }
  85.  
  86.     /**
  87.      * Closes the stream.
  88.      */
  89.     public void close() throws IOException {
  90.     impl.close();
  91.     }
  92.  
  93.     /** 
  94.      * Overrides finalize, the fd is closed by the Socket.
  95.      */
  96.     protected void finalize() {}
  97. }
  98.